import { createStore } from 'vuex'
import createPersistedState from "vuex-persistedstate";

export default createStore({
  state: {
    // 用户信息
    userInfo: null,
    // 令牌
    token: null,
    // 底部弹起列表的配置
    actionSheetConfig: {
      // 是否展示
      isShow: false,
      // 展示什么
      list: [],
      // 成功选中后触发的回调
      successCallBack: null
    },
    // 地址
    addressInfo: null,
    // 当前订单选中的购买地址
    currentAddresss: null
  },
  getters: {
  },
  mutations: {
    setCurrentAddress(state, currentAddresss) {
      state.currentAddresss = currentAddresss
    },
    setAddressInfo(state, addressInfo) {
      state.addressInfo = addressInfo
    },
    showActionSheet(state, config) {
      state.actionSheetConfig.isShow = true
      state.actionSheetConfig.list = config.list
      state.actionSheetConfig.successCallBack = config.success
    },
    hideActionSheet(state) {
      state.actionSheetConfig.isShow = false
      state.actionSheetConfig.list = []
    },
    setUserInfo(state, userInfo) {
      state.userInfo = userInfo
    },
    setToken(state, token) {
      state.token = token
    },
    logOut(state) {
      state.userInfo = null
      state.token = null
    }
  },
  actions: {
  },
  modules: {
  },
  plugins: [createPersistedState({
    paths: ['token', 'userInfo'],
    // 开发阶段，可能反复的调试，可以使用sessionStorage
    storage: window.localStorage
  })],
})
